<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="col-sm-12">
        <div class="ibox">
            <div class="ibox-body">
                <div class="fixed-table-toolbar">
                    <table class="table table-bordered">
                        <caption>用户基本信息</caption>
                        <tr>
                            <td width="90">商户号：</td>
                            <td><span th:text="${merchant.merchNo}"></span></td>
                            <td width="90">商户名称：</td>
                            <td><span th:text="${merchant.merchantsName}"></span></td>
                            <td width="90">余额(元)：</td>
                            <td><span th:text="${merchant.balance}"></span></td>
                            <td width="120">可用余额(元)：</td>
                            <td><span th:text="${merchant.availBal}"></span></td>
                        </tr>
                        <tr>
                            <td>RSA公钥：</td>
                            <td colspan="7" style="word-break:break-all;" th:text="${merchant.publicKey}"></td>
                        </tr>
                    </table>
                </div>
                <table id="exampleTable" data-mobile-responsive="true">
                    <caption>支付渠道信息</caption>
                </table>
            </div>
        </div>
    </div>
</div>

</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    /*<![CDATA[*/
    var merchant = [[${merchant}]];
    var outChannels = [[${outChannels}]]
    /*]]>*/
</script>

<script type="text/javascript">
$(function(){
    var handRate = merchant.handRate;
    var channelSwitch = merchant.channelSwitch;

    var data = [];

    for(var key in outChannels){
        var obj = {};
        obj.outChannel = outChannels[key];
        obj.handRate = handRate[key];
        obj.channelSwitch = channelSwitch[key];
        data.push(obj);
    }
    data.sort(sortBy('channelSwitch',sortBy('outChannel')))

    $('#exampleTable').bootstrapTable({
        iconSize : 'outline',
        striped : true, // 设置为true会有隔行变色效果
        dataType : "json", // 服务器返回的数据类型
        showColumns : false, // 是否显示内容下拉框（选择显示的列）
        columns : [
            {
                field : 'outChannel',
                title : '支付渠道'
            },
            {
                field : 'handRate',
                title : '手续费率'
            },
            {
                field : 'channelSwitch',
                title : '渠道状态',
                formatter : function(value, row, index){
                    if(value==1){
                        return '<span class="label label-primary">正常</span>';
                    }else{
                        return '<span class="label label-danger">禁用</span>';
                    }
                }
            }]
    });
    $('#exampleTable').bootstrapTable('load',data);
})

function sortBy(name,minor){
    return function(o,p){
        var a,b;
        if(o && p && typeof o === 'object' && typeof p ==='object'){
            a = o[name];
            b = p[name];
            if(a === b){
                return typeof minor === 'function' ? minor(o,p):0;
            }
            if(typeof a === typeof b){
                return a < b ? -1:1;
            }
            return typeof a < typeof b ? -1 : 1;
        }else{
            throw("error");
        }
    }
}

</script>
</body>
</html>